import { WuXingBasePanel } from "./WuXingBasePanel";
import { TodayNotTipUtil } from "../../../common/TodayNotTipUtil";
import { TodayNoTipsConst } from "../../../component/gconst/TodayNoTipsConst";
import { Language } from "../../../../extend/language/Language";
import { Alert } from "../../../../com/mui/controls/Alert";
import { EffectManager } from "../../manager/EffectManager";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { WuXingSkillItem2 } from "./WuXingSkillItem2";
import { WuXingRefreshAttrPanel } from "./WuXingRefreshAttrPanel";
import { WuXingRefreshList } from "./WuXingRefreshList";
import { ObjCreate } from "../common/ObjCreate";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { WuXingQualityBuyPanel } from "./WuXingQualityBuyPanel";
import { ECategory } from "../../../../Message/Public/ECategory";
import { EProp } from "../../../../Message/Public/EProp";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { PetMingMsgRollTips } from "../pet/ming/PetMingMsgRollTips";
import { WuXingPlayerInfo } from "../../model/wuxing/WuXingPlayerInfo";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
import { GCheckBox } from "../../../../com/mui/controls/GCheckBox";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class WuXingRefreshPanel
    
    export  class WuXingRefreshPanel extends WuXingBasePanel
    {
        constructor(arg1: int=428, arg2: int=438)
        {
            super(arg1, arg2);
            return;
        }

        /* internal  */onReplaceBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (_info && _info.getNewAttrFightValue(this._newAttrPanel.index) > 0) 
            {
                if (_info.vitalsAddition > _info.getNewVitalsAddition(this._newAttrPanel.index)) 
                {
                    TodayNotTipUtil.toDayNotTip(TodayNoTipsConst.WuXingReplaceNotTip, this.replaceReq, Language.getString(26418), null, Alert.OK | Alert.CANCEL);
                }
                else 
                {
                    this.replaceReq();
                }
            }
            EffectManager.glowFilterUnReg(this._refreshBtn);
            return;
        }

        /* internal  */replaceReq(): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.WuXingAttrReplaceReq, this._newAttrPanel.index));
            return;
        }

        /* internal  */onRefreshGroupBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.WuXingRefreshGroupOpenReq));
            return;
        }

        protected onWuXingBgLoadedHandler(): void
        {
            this._skillItemBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.wxMingMaiCur);
            return;
        }

        protected onFrameLodedHandler(): void
        {
            this._frameLoaded = true;
            this.updateSkillItem();
            return;
        }

        /* internal  */updateSkillItem(): void
        {
            var loc1=null;
            if (!_info || !this._frameLoaded) 
            {
                return;
            }
            if (!this._skillItem || !(this._skillItem.index == _info.mainAttribute)) 
            {
                if (this._skillItem) 
                {
                    removeChild(this._skillItem);
                }
                loc1 = GlobalClass.getInstance("wxSkill_" + _info.mainAttribute);
                this._skillItem = new WuXingSkillItem2(loc1, _info.mainAttribute);
                this._skillItem.y = this._skillItemBmp.y + 20;
                this._skillItem.x = this._skillItemBmp.x + 18;
                addChild(this._skillItem);
            }
            this._skillItem.updateData(_info);
            return;
        }

        protected /* override */ initUI(): void
        {
            super.initUI();
            this._skillItemBmp = new Object /* flash.display.Bitmap */();
            this._skillItemBmp.y = 10;
            this._skillItemBmp.x = 290;
            addChild(this._skillItemBmp);
            this._attrPanel = new WuXingRefreshAttrPanel(_bg1.width, 136);
            this._attrPanel.x = _bg1.x;
            this._attrPanel.y = _bg1.y;
            addChild(this._attrPanel);
            this._curAttrPanel = new WuXingRefreshList(0, 160, 166);
            this._curAttrPanel.x = width / 2 - this._curAttrPanel.width - 20;
            this._curAttrPanel.y = _bg1.y + 150;
            addChild(this._curAttrPanel);
            this._newAttrPanel = new WuXingRefreshList(1, this._curAttrPanel.width, this._curAttrPanel.height);
            this._newAttrPanel.x = width / 2 + 20;
            this._newAttrPanel.y = this._curAttrPanel.y;
            addChild(this._newAttrPanel);
            this._lockMainAttr = ObjCreate.createCheckBox(Language.getString(26337), this._curAttrPanel.x, this._curAttrPanel.y - 25, 110, 22, null);
            this._lockMainAttr.textField.filters = [FilterConst.nameGlowFilter];
            this._lockMainAttr.addEventListener(flash.events.Event.CHANGE, this.onLockMainAttrChangeHandler);
            this._refreshBtn = ObjCreate.createGButton(Language.getString(26339), 0, 0, 65, 22, this, "ButtonRedMini");
            this._refreshBtn.x = this.width / 2 - this._refreshBtn.width - 50;
            this._refreshBtn.y = this._curAttrPanel.y + this._curAttrPanel.height + 20;
            this._refreshBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onRefreshBtnClickHandler);
            this._replaceBtn = ObjCreate.createGButton(Language.getString(26340), 0, 0, 65, 22, this, "ButtonRedMini");
            this._replaceBtn.x = this.width / 2 + 50;
            this._replaceBtn.y = this._refreshBtn.y;
            this._replaceBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onReplaceBtnClickHandler);
            this._refreshGroupBtn = ObjCreate.createGButton(Language.getString(26372), 0, 0, 65, 22, this, "ButtonRedMini");
            this._refreshGroupBtn.x = (this.width - this._refreshGroupBtn.width) / 2;
            this._refreshGroupBtn.y = this._refreshBtn.y;
            this._refreshGroupBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onRefreshGroupBtnClickHandler);
            var loc1=ResouceConst.getScaleBitmap(ImagesConst.DisabledBg);
            loc1.setSize(360, 56);
            addChild(loc1);
            this._buyPanel = new WuXingQualityBuyPanel(ECategory._ECategoryProp, EProp._EPropWuXingAttributeRefresh, false, false, false);
            this._buyPanel.x = this._curAttrPanel.x + 5;
            this._buyPanel.y = this._curAttrPanel.y + this._curAttrPanel.height + 50;
            addChild(this._buyPanel);
            this._buyPanel.updateNeedCount(1);
            loc1.x = this._buyPanel.x - 5;
            loc1.y = this._buyPanel.y + 10;
            this._autoBuy = ObjCreate.createCheckBox(Language.getString(26338), 265, height - 35, 140, 22, this);
            this._autoBuy.textField.filters = [FilterConst.nameGlowFilter];
            this._autoBuy.addEventListener(flash.events.Event.CHANGE, this.onAutoBuyChangeHandler);
            LoaderHelp.addResCallBack(ResFileConst.wuxing, this.onWuXingBgLoadedHandler);
            LoaderHelp.addResCallBack("wuxingbg.swf", this.onFrameLodedHandler);
            this._msgRollTips = new PetMingMsgRollTips();
            this._msgRollTips.x = this._refreshBtn.x;
            this._msgRollTips.y = this._refreshBtn.y - 20;
            this.addChild(this._msgRollTips);
            return;
        }

        public /* override */ updateData(arg1: WuXingPlayerInfo): void
        {
            if (!arg1) 
            {
                return;
            }
            this._refreshBtn.enabled = true;
            this._replaceBtn.enabled = true;
            super.updateData(arg1);
            this.updateSkillItem();
            this.updateMainAttr();
            this.updateAttrList(arg1, false);
            this.onAutoBuyChangeHandler(null);
            return;
        }

        public /* override */ updateAttrList(arg1: WuXingPlayerInfo, arg2: Boolean=true): void
        {
            super.updateAttrList(arg1, arg2);
            _info = arg1;
            if (_info) 
            {
                this._attrPanel.updateData(arg1);
                if (!arg2) 
                {
                    this._curAttrPanel.updateData(_info);
                    this.onLockMainAttrChange();
                }
                this._newAttrPanel.updateData(_info, _info.getNewAttrFrist());
            }
            return;
        }

        public /* override */ updatePackData(): void
        {
            this._buyPanel.updatePackData();
            return;
        }

        public /* override */ showEffect(): void
        {
            super.showEffect();
            EffectManager.glowFilterReg(this._refreshBtn, null, 0.6, 10, 5, 10);
            return;
        }

        public /* override */ onLockMainAttrChange(): void
        {
            if (_info) 
            {
                if (_info.lockMainAttr) 
                {
                    this.changeLockMainAttr(Alert.OK, false);
                }
                else 
                {
                    this.changeLockMainAttr(Alert.CANCEL, false);
                }
            }
            return;
        }

        public /* override */ onAutoBuyChange(): void
        {
            if (_info) 
            {
                this._autoBuy.selected = _info.autoBuy;
            }
            return;
        }

        public /* override */ dispose(): void
        {
            super.dispose();
            EffectManager.glowFilterUnReg(this._refreshBtn);
            return;
        }

        public /* override */ showMsg(arg1: string): void
        {
            this._msgRollTips.showMsg(arg1, 1);
            return;
        }

        /* internal  */updateMainAttr(): void
        {
            return;
        }

        /* internal  */onLockMainAttrChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            if (this._lockMainAttr.selected) 
            {
                Alert.buttonWidth = 100;
                Alert.show(Language.getString(26332), null, Alert.OK | Alert.CANCEL, null, this.changeLockMainAttr);
            }
            else 
            {
                this.changeLockMainAttr(Alert.CANCEL);
            }
            return;
        }

        /* internal  */changeLockMainAttr(arg1: int, arg2: Boolean=true): void
        {
            if (arg1 != Alert.CANCEL) 
            {
                this._lockMainAttr.selected = true;
            }
            else 
            {
                this._lockMainAttr.selected = false;
            }
            _info.lockMainAttr = this._lockMainAttr.selected;
            this._curAttrPanel.updateLockMainAttr();
            if (arg2) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.WuXingLockMainAttrChange));
            }
            return;
        }

        /* internal  */onAutoBuyChangeHandler(arg1: Object /* flash.events.Event */=null): void
        {
            if (arg1) 
            {
                _info.autoBuy = this._autoBuy.selected;
            }
            else 
            {
                this._autoBuy.selected = _info.autoBuy;
            }
            if (arg1) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.WuXingAutoBuyChange));
            }
            return;
        }

        /* internal  */onRefreshBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._refreshBtn.enabled = false;
            this._replaceBtn.enabled = false;
            EffectManager.glowFilterUnReg(this._refreshBtn);
            var loc1=_info.getNewAttrFightValue(0);
            if (_info.fightValue < loc1) 
            {
                Alert.buttonWidth = 80;
                Alert.show(Language.getStringByParam(26363, loc1), null, Alert.OK | Alert.CANCEL, null, this.onRefreshAlert);
                return;
            }
            this.onRefreshAlert(Alert.OK);
            return;
        }

        /* internal  */onRefreshAlert(arg1: int): void
        {
            this._refreshBtn.enabled = true;
            this._replaceBtn.enabled = true;
            if (arg1 == Alert.OK) 
            {
                _info.autoBuy = this._autoBuy.selected;
                if (_info.autoBuy) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.WuXingAttrRefreshReq));
                }
                else if (this._buyPanel.amount > 0) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.WuXingAttrRefreshReq));
                }
                else 
                {
                    this._buyPanel.buyItem(1, true);
                }
            }
            return;
        }

        /* internal */ /* var */_bg2: ScaleBitmap;

        /* internal */ /* var */_attrPanel: WuXingRefreshAttrPanel;

        /* internal */ /* var */_skillItemBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_skillItem: WuXingSkillItem2;

        /* internal */ /* var */_frameLoaded: Boolean;

        /* internal */ /* var */_lockMainAttr: GCheckBox;

        /* internal */ /* var */_curAttrPanel: WuXingRefreshList;

        /* internal */ /* var */_newAttrPanel: WuXingRefreshList;

        /* internal */ /* var */_changeAttrBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_autoBuy: GCheckBox;

        /* internal */ /* var */_buyPanel: WuXingQualityBuyPanel;

        /* internal */ /* var */_refreshBtn: GButton;

        /* internal */ /* var */_replaceBtn: GButton;

        /* internal */ /* var */_refreshGroupBtn: GButton;

        /* internal */ /* var */_msgRollTips: PetMingMsgRollTips;
    }
